# coding:utf-8
import numpy as np
import json
from collections import defaultdict
from keras.layers import *
from keras.models import Sequential
from keras.models import load_model
from keras.preprocessing.sequence import pad_sequences
from keras.optimizers import SGD
import numpy as np
import tensorflow as tf
from keras.backend.tensorflow_backend import set_session
config = tf.ConfigProto()
config.gpu_options.per_process_gpu_memory_fraction = 0.4
set_session(tf.Session(config=config))
ner_weights = np.load('ner_weights.npy')
word2id = json.load(open('word2id.json'))
word2id = defaultdict(lambda: len(word2id)+1, word2id)
text = u'自感寒热，伴有四肢僵硬'
nb_word = len(word2id) + 2
embedding_size = 64
sentence_length = 150
model = load_model('ner_model')
model.summary()
words = [[word2id[i] for i in text]]
words = pad_sequences(words, sentence_length)
firstWordIndex = np.where(words!=0)[1][0]
result = model.predict(words)
tmp = np.argmax(result, axis=2)
index = np.where(tmp!=0)[1]
index = index - firstWordIndex - 1
text = np.array(list(text))
print result
for ch in text[index] :
    print ch,